package com.fly.server.controller;

import com.fly.server.domain.User;
import com.fly.server.service.UserService;
import com.fly.server.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName UserController
 * @Description TODO
 * @Author Fly
 * @Version
 * @Date 2019-12-26 0026 10:24
 */
@RequestMapping("users")
@RestController
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 新增
     * @param user
     * @return
     */
    @PostMapping()
    public Result<User> create(@RequestBody()User user){
        userService.saveUser(user);
        return Result.ok();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public Result<User> delete(@PathVariable("id")String id){
        userService.removeUser(id);
        return Result.ok();
    }

    /**
     * 查找
     * @return
     */
    @GetMapping()
    public Result<List<User>> list(){
        return Result.ok(userService.selectList());
    }
}
